package actions.members;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import veilingAware.UserAware;
import veilingDomein.Krediet;
import veilingDomein.User;
import veilingService.IVeilingService;
import veilingService.ServiceProvider;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class Credit extends ActionSupport implements UserAware {

	private int aantal;
	User user;

	public String execute() {
		System.out.println("Credits kopen :)");
		Krediet k = user.getKrediet();
		k.stort(aantal);
		user.setKrediet(k);
		ServiceProvider.getVeilingService().kredietFactuurToevoegen(user,
				aantal);

		return ActionSupport.SUCCESS;
	}

	public void validate() {
		if (aantal < 0) {
			addFieldError("aantal", "U kan geen negatieve credits kopen.");
		}
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public int getAantal() {
		return aantal;
	}

	public void setAantal(int aantal) {
		this.aantal = aantal;
	}
}
